home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / proc / machTypeMips.c < prev    next >
C/C++ Source or Header  |  1991-03-16  |  3KB  |  116 lines

  1. /* 
  2.  * machTypeMips.c --
  3.  *
  4.  *    Contains the machine specific routine for determining if
  5.  *      a file is an object file for a decStation 3100.
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/attcmds/file/RCS/machTypeMips.c,v 1.4 90/10/19 15:25:44 jhh Exp Locker: shirriff $";
  19. #endif /* not lint */
  20.  
  21. #include <assert.h>
  22. #ifdef KERNEL
  23. #include <sys.h>
  24. #endif
  25.  
  26. /*
  27.  * Hack warning:  we have to define mips, LANGUAGE_C, and MIPSEL in order
  28.  * to get the proper ds3100 header files.  We must then undefine mips if
  29.  * this isn't a ds3100.
  30.  */
  31. #ifndef mips
  32. #define mips 1
  33. #define notreallymips
  34. #endif
  35.  
  36. #ifndef LANGUAGE_C
  37. #define LANGUAGE_C
  38. #endif
  39.  
  40. #ifndef MIPSEL
  41. #define MIPSEL
  42. #endif
  43.  
  44. #include <ds3100.md/sys/exec.h>
  45. #include <ds3100.md/a.out.h>
  46.  
  47. #ifdef notreallymips
  48. #undef mips
  49. #endif
  50.  
  51. #include "file.h"
  52.  
  53.  
  54. /*
  55.  *----------------------------------------------------------------------
  56.  *
  57.  * machTypeMips --
  58.  *
  59.  *    Determine if the file is a mips-specific file type.
  60.  *
  61.  * Results:
  62.  *    If successful, return the name of the machine.  Otherwise
  63.  *      return NULL.
  64.  *
  65.  * Side effects:
  66.  *    Modifies the `magic' number.
  67.  *
  68.  *----------------------------------------------------------------------
  69.  */
  70.  
  71. char *
  72. machTypeMips(bufferSize, buffer, magic, syms, other)
  73.     int        bufferSize;    /* size of buffer */
  74.     char    *buffer;    /* buffer containing header */
  75.     int         *magic;         /* pointer to magic number */
  76.     int         *syms;          /* pointer to symbols */
  77.     char    **other;    /* other information to return */
  78. {
  79.  
  80.     struct exec        *header;
  81.     char        swappedHeader[sizeof(*header) * 2];
  82.     int            swappedSize = sizeof(swappedHeader);
  83.     int            status;
  84.  
  85.     *other = "";
  86.  
  87.     assert(HEADERSIZE >= sizeof(struct exec));
  88.     if (bufferSize < sizeof(struct exec)) {
  89.     return NULL;
  90.     }
  91.     header = (struct exec *) buffer;
  92.     if (!N_BADMAG((header->ex_o))) {
  93.     *magic = header->a_magic;
  94.     *syms = header->ex_f.f_nsyms;
  95.     return "mips";
  96.     }
  97.     if (FMT_MIPS_FORMAT != hostFmt) {
  98.     status = Fmt_Convert("{h2w3h2h2w13}", FMT_MIPS_FORMAT, &bufferSize,
  99.         (char *) buffer, hostFmt, &swappedSize, swappedHeader);
  100.     if (status) {
  101. #ifndef KERNEL
  102.         fprintf(stderr, "Fmt_Convert returned %d.\n", status);
  103. #endif
  104.         return NULL;
  105.     }
  106.     header = (struct exec *) swappedHeader;
  107.     if (!N_BADMAG((header->ex_o))) {
  108.         *magic = header->a_magic;
  109.         *syms = header->ex_f.f_nsyms;
  110.         return "mips";
  111.     }
  112.     }
  113.     return NULL;
  114. }
  115.  
  116.